package mapper;

import BO.QuestionNumberBO;
import DO.EncodeQuestionDO;
import DTO.AddEncodeDTO;
import DTO.PageJudgeQuestionDTO;
import DTO.UpdateEncodeQuestionDTO;
import VO.ChooseQuestionVO;
import VO.EncodeQuestionVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface EncodeQuestionMapper {
    // 获取分页查询总数
    Integer getTotal(PageJudgeQuestionDTO pageQuestionDTO);

    // 分页查询，获取数据
    List<EncodeQuestionVO> page(PageJudgeQuestionDTO pageQuestionDTO);

    // 修改编程题
    void updateEncodeQuestion(UpdateEncodeQuestionDTO updateEncodeQuestionDTO);

    // 更新表中编程题的测试用例的个数信息
    @Update("update encode_question set orders = #{number} where id = #{id}")
    void updateOrders(int number, Integer id);

    // 获取测试数量
    @Select("select orders from encode_question where id = #{id}")
    Integer getOrderById(Integer id);

    // 获取所有编号
    @Select("select question_number from encode_question")
    List<String> getQuestionNumber();

    // 添加编程题
    void insert(EncodeQuestionDO encodeQuestionDO);

    // 获取所有编号和id
    @Select("select id,question_number from encode_question where chapter>= #{startRange} and chapter<= #{endRange} order by question_number")
    List<QuestionNumberBO> getQuestionNumberAndId(Integer startRange,Integer endRange);

    // 根据id 获取编程题数据
    @Select("select * from encode_question where id = #{id}")
    EncodeQuestionDO getById(Integer id);

    @Update("update encode_question set submit = submit + 1,pass = pass +1 where id = #{encodeId}")
    void editAdd1(Integer encodeId);

    @Update("update encode_question set submit = submit + 1 where id = #{encodeId}")
    void editMinus(Integer encodeId);
}
